//
//  BreakfastBars.m
//  JackDeve
//
//  Created by Agensn on 2017/5/12.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "BreakfastBarsView.h"

@interface BreakfastBarsView()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation BreakfastBarsView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.dataDic = [NSDictionary new];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selfData:) name:@"SDBreakData" object:nil];
        
        [self addSubview:self.headerView];
        self.headerView.sd_layout.topSpaceToView(self, 0).leftSpaceToView(self, 0).rightSpaceToView(self, 0).heightIs(SCREEN_HEIGHT*0.126/0.649);
        
        [self addSubview:self.leftTable];
        self.leftTable.sd_layout.leftSpaceToView(self, 0).topSpaceToView(self.headerView, 0).widthIs(self.bounds.size.width*0.23).heightIs(self.bounds.size.height-SCREEN_HEIGHT*0.126/0.649);
        
        [self addSubview:self.rightTable];
        self.rightTable.sd_layout.leftSpaceToView(self.leftTable, 0).heightIs(self.bounds.size.height-SCREEN_HEIGHT*0.126/0.649).widthIs(self.bounds.size.width*0.77).topSpaceToView(self.headerView, 0);
    }
    return self;
}

-(void)selfData:(NSNotification *)object{
    self.dataDic = object.object;
    [self.leftTable reloadData];
    [self.rightTable reloadData];
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.leftTable) {
        return 7;
    }else
        return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *str = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        if (tableView == self.leftTable) {
            cell.textLabel.text = @"left";
        }else if(tableView == self.rightTable){
            cell.textLabel.text = @"right";
        }
    });

    
    
    return cell;
}
//  点击单元格的时候取消选中单元格
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.leftTable) {
        return 30;
    }else
        return 80;
}



-(UIImageView *)headerView{
    if (!_headerView) {
        _headerView = [[UIImageView alloc]init];
        _headerView.image = [UIImage imageNamed:@"wallhaven"];
        
        UIImageView *head = [[UIImageView alloc]init];
        head.layer.cornerRadius = 25;
        head.layer.masksToBounds = YES;
        head.image = [UIImage imageNamed:@"0D418D24-5D22-4E1E-805B-9F0B751C7D16"];
        [self.headerView addSubview:head];
        head.sd_layout.bottomSpaceToView(self.headerView, 20).leftSpaceToView(self.headerView, 20).widthIs(50).heightIs(50);
        
        UILabel *shopAddress = [[UILabel alloc]init];
        shopAddress.textAlignment = NSTextAlignmentLeft;
        shopAddress.textColor = [UIColor whiteColor];
        shopAddress.font = [UIFont systemFontOfSize:30];
        shopAddress.font = [UIFont boldSystemFontOfSize:20];
        shopAddress.text = @"dizhishizheliaaaaa";
        [self.headerView addSubview:shopAddress];
        shopAddress.sd_layout.topEqualToView(head).leftSpaceToView(head, 15).heightIs(30).widthIs(200);
        
        UIImageView *addressImg = [[UIImageView alloc]init];
        addressImg.image = [UIImage imageNamed:@"地址"];
        [self.headerView addSubview:addressImg];
        addressImg.sd_layout.leftEqualToView(shopAddress).bottomEqualToView(head).widthIs(15).heightIs(15);
        
    }
    return _headerView;
}
-(UITableView *)leftTable{
    if (!_leftTable) {
        _leftTable = [[UITableView alloc]init];
        _leftTable.delegate = self;
        _leftTable.dataSource = self;
    }
    return _leftTable;
}
-(UITableView *)rightTable{
    if (!_rightTable) {
        _rightTable = [[UITableView alloc]init];
        _rightTable.delegate = self;
        _rightTable.dataSource = self;
    }
    return _rightTable;
}
@end
